﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SlackOff
{
    public class SlackOffTimeState : ITimeState
    {
        private ITimeStateContext context;
        private readonly TimeLeft timeLeft;
        public SlackOffTimeState(ITimeStateContext context)
            : this(context, context.Options.SlackOffMinutes)
        {
        }

        public SlackOffTimeState(ITimeStateContext context, int classTimeMinutes)
        {
            this.context = context;
            this.timeLeft = new TimeLeft(classTimeMinutes, this.context.Options.SlackOffDelayingMinutes);
            this.timeLeft.Start();
        }

        public Status Status => Status.SlackOffTime;

        public string GetDescription()
        {
            return this.timeLeft.GetTimeLeft().ToString();
        }

        public void Start()
        {

        }

        public void TryFinish()
        {
            if (this.timeLeft.GetTimeLeft().IsOver)
            {
                this.context.ChangeState(new SlackOffFinishState(this.context));
            }
        }

        public bool CanStart
        {
            get
            {
                return false;
            }
        }

        public void Delay()
        {
            this.timeLeft.Delay();
        }

        public bool CanDelay
        {
            get
            {
                return true;
            }
        }

        public string StartButtonText => this.context.Options.SlackOffTimeStartButtonText;
        public string DelayButtonText => String.Format(this.context.Options.SlackOffTimeDelayButtonText, this.context.Options.SlackOffDelayingMinutes);

    }
}
